% font features for the chinese main fonts

\definefontfeature[zh][mode=node,script=hani,lang=zhs]


% Character ranges for the fallback font, I prefer the first definition
% but which ranges are needed

\def\latinfallback{latinextendeda,latinextendedb,latinextendedc,latinextendedd}
\def\latinfallback{0x0000-0x0400} 


% Mapping of the fallback fonts to Latin... synonyms, should be done in type-otf

\starttypescript [serif] [pagella,palatino,termes,times]
  \definefontsynonym [LatinSerif-Regular]    [\typescriptprefix{n:\typescripttwo}-Regular]
  \definefontsynonym [LatinSerif-Italic]     [\typescriptprefix{n:\typescripttwo}-Italic]
  \definefontsynonym [LatinSerif-Bold]       [\typescriptprefix{n:\typescripttwo}-Bold]
  \definefontsynonym [LatinSerif-BoldItalic] [\typescriptprefix{n:\typescripttwo}-BoldItalic]
\stoptypescript

\starttypescript [sans] [heros,helvetica]
  \definefontsynonym [LatinSans-Regular]     [\typescriptprefix{n:\typescripttwo}-Regular]
  \definefontsynonym [LatinSans-Italic]      [\typescriptprefix{n:\typescripttwo}-Italic]
  \definefontsynonym [LatinSans-Bold]        [\typescriptprefix{n:\typescripttwo}-Bold]
  \definefontsynonym [LatinSans-BoldItalic]  [\typescriptprefix{n:\typescripttwo}-BoldItalic]
\stoptypescript

\starttypescript [mono] [cursor,courier]
  \definefontsynonym [LatinMono-Regular]     [\typescriptprefix{n:\typescripttwo}-Regular]
  \definefontsynonym [LatinMono-Italic]      [\typescriptprefix{n:\typescripttwo}-Italic]
  \definefontsynonym [LatinMono-Bold]        [\typescriptprefix{n:\typescripttwo}-Bold]
  \definefontsynonym [LatinMono-BoldItalic]  [\typescriptprefix{n:\typescripttwo}-BoldItalic]
\stoptypescript


% Fallback names

\definefontfallback [WesternSerif]           [LatinSerif-Regular]    [\latinfallback] [force=yes]
\definefontfallback [WesternSerifBold]       [LatinSerif-Bold]       [\latinfallback] [force=yes]
\definefontfallback [WesternSerifItalic]     [LatinSerif-Italic]     [\latinfallback] [force=yes]
\definefontfallback [WesternSerifBoldItalic] [LatinSerif-BoldItalic] [\latinfallback] [force=yes]

\definefontfallback [WesternSans]            [LatinSans-Regular]     [\latinfallback] [force=yes]
\definefontfallback [WesternSansBold]        [LatinSans-Bold]        [\latinfallback] [force=yes]
\definefontfallback [WesternSansItalic]      [LatinSans-Italic]      [\latinfallback] [force=yes]
\definefontfallback [WesternSansBoldItalic]  [LatinSans-BoldItalic]  [\latinfallback] [force=yes]

\definefontfallback [WesternMono]            [LatinMono-Regular]     [\latinfallback] [force=yes]
\definefontfallback [WesternMonoBold]        [LatinMono-Bold]        [\latinfallback] [force=yes]
\definefontfallback [WesternMonoItalic]      [LatinMono-Italic]      [\latinfallback] [force=yes]
\definefontfallback [WesternMonoBoldItalic]  [LatinMono-BoldItalic]  [\latinfallback] [force=yes]


% Chinese fonts
 
\starttypescript [serif] [zhfont]
  \setups[font:fallback:serif]
  \definefontsynonym [Serif]           [ZhSerif]           [fallbacks=WesternSerif]
  \definefontsynonym [SerifBold]       [ZhSerifBold]       [fallbacks=WesternSerifBold]
  \definefontsynonym [SerifItalic]     [ZhSerifItalic]     [fallbacks=WesternSerifItalic]
  \definefontsynonym [SerifBoldItalic] [ZhSerifBoldItalic] [fallbacks=WesternSerifBoldItalic]
\stoptypescript

\starttypescript [serif] [zhfont]
  \definefontsynonym [ZhSerif]           [name:AdobeSongStd-Light]    [features=zh]
  \definefontsynonym [ZhSerifBold]       [name:AdobeHeitiStd-Regular] [features=zh]
  \definefontsynonym [ZhSerifItalic]     [name:AdobeKaitiStd-Regular] [features=zh]
  \definefontsynonym [ZhSerifBoldItalic] [name:AdobeHeitiStd-Regular] [features=zh]
\stoptypescript

\starttypescript [sans] [zhfont]
  \setups[font:fallback:sans]
  \definefontsynonym [Sans]           [ZhSans]           [fallbacks=WesternSans]
  \definefontsynonym [SansBold]       [ZhSansBold]       [fallbacks=WesternSansBold]
  \definefontsynonym [SansItalic]     [ZhSansItalic]     [fallbacks=WesternSansItalic]
  \definefontsynonym [SansBoldItalic] [ZhSansBoldItalic] [fallbacks=WesternSansBoldItalic]
\stoptypescript

\starttypescript [sans] [zhfont]
  \definefontsynonym [ZhSans]           [name:AdobeKaitiStd-Regular] [features=zh]
  \definefontsynonym [ZhSansBold]       [name:AdobeHeitiStd-Regular] [features=zh]
  \definefontsynonym [ZhSansItalic]     [name:AdobeKaitiStd-Regular] [features=zh]
  \definefontsynonym [ZhSansBoldItalic] [name:AdobeHeitiStd-Regular] [features=zh]
\stoptypescript

\starttypescript [mono] [zhfont]
  \setups[font:fallback:mono]
  \definefontsynonym [Mono]           [ZhMono]           [fallbacks=WesternMono]
  \definefontsynonym [MonoBold]       [ZhMonoBold]       [fallbacks=WesternMonoBold]
  \definefontsynonym [MonoItalic]     [ZhMonoItalic]     [fallbacks=WesternMonoItalic]
  \definefontsynonym [MonoBoldItalic] [ZhMonoBoldItalic] [fallbacks=WesternMonoBoldItalic]
\stoptypescript

\starttypescript [mono] [zhfont]
  \definefontsynonym [ZhMono]           [name:AdobeFangsongStd-Regular] [features=zh]
  \definefontsynonym [ZhMonoBold]       [name:AdobeHeitiStd-Regular]    [features=zh]
  \definefontsynonym [ZhMonoItalic]     [name:AdobeFangsongStd-Regular] [features=zh]
  \definefontsynonym [ZhMonoBoldItalic] [name:AdobeHeitiStd-Regular]    [features=zh]
\stoptypescript

\starttypescript[myfont]
  \definetypeface [myfont] [rm] [serif] [zhfont] [default]
  \definetypeface [myfont] [ss] [sans]  [zhfont] [default]
  \definetypeface [myfont] [tt] [mono]  [zhfont] [default]

  \spaceskip .25em plus .25em\relax
  \let\synchronizetext\relax
\stoptypescript

\doifnotmode{demo}{\endinput}

% test

\usetypescript[serif][times]     % serif fallback
\usetypescript[sans] [helvetica] % sans  fallback

\usetypescript[myfont]
\setupbodyfont[myfont]

\starttext

\rm 兡也包因沘氓侷柵苗孫孫財 text 兡也包因沘氓侷柵苗孫孫財

\ss 兡也包因沘氓侷柵苗孫孫財 text 兡也包因沘氓侷柵苗孫孫財

\stoptext
